<template>
	<view class="shopping-comment">
		<u-popup :show="show" mode="bottom" :overlay="true" round="30rpx" @open="open">
			<view class="box">
				<view class="" style="height: 32rpx;"></view>
				<view class="header">
					<view class="title">评价</view>
					<view class="icon-close" @click="close">
						<u-icon name="close" size="12" color="#BDBDBD"></u-icon>
					</view>
				</view>
				<view class="" style="height: 40rpx;"></view>
				<view class="list">
					<view class="list-item" v-for="(item,index) in listData" :key="index">
						<image class="image" :src="item.goodsPic" mode="aspectFill"></image>
						<view class="tips">
							<view class="text">{{item.goodsName}}</view>
							<view>
								<u-rate :count="5" v-model="item.goodsStar"></u-rate>
							</view>
						</view>
					</view>
				</view>
				<view class="btn" @click="handleAdd">确定</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		listOrderInfo,
		addtWcComment
	} from "@/culturalCreativity/http/my.js";
	import {
		realmName
	} from "@/http";
	const GET_KEYS = () => {
		return Object.keys({
			"creator": "string",
			"creatorId": "string",
			"creatorTime": "2023-09-09T04:13:43.803Z",
			"deleteFlag": "string",
			"f1": "string",
			"f2": "string",
			"f3": "string",
			"goodsId": 0,
			"goodsName": "string",
			"goodsPercent": "string",
			"goodsStar": "string",
			"goodsType": "string",
			"id": 0,
			"modifyOperator": "string",
			"modifyOperatorId": "string",
			"modifyTime": "2023-09-09T04:13:43.803Z",
			"orderId": "string",
			"sort": "string",
			"specificationName":""
		})
	}
	export default {
		data() {
			return {
				show: false,
				val: 1,
				userInfo: uni.getStorageSync('userInfo'),
				options: {},
				listData: [],
			}
		},
		methods: {
			async init(options, item) {
				try {
					this.options = options;
					if (item) {
						this.listData = [item];
						this.show = true;
						return;
					}
					uni.showLoading({
						title: " ",
						mask: true
					});
					let res = await listOrderInfo({
						orderId: options.orderId
					});
					this.listData = res.data.data.resultList;
					uni.hideLoading();
					this.show = true;
				} catch (e) {
					console.error('error', e)
					uni.hideLoading();
				}
			},
			async handleAdd() {
				uni.showLoading({
					title: "正在加载...",
					mask: true
				});
				let data = this.listData.map(async item => {
					let form = {};
					GET_KEYS().forEach(key => {
						form[key] = item[key];
					});
					return await addtWcComment(form)
				})
				let res = await Promise.all(data);
				console.log('评价商品', res);
				uni.hideLoading();
				this.$emit("submit");
				this.show = false;
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false;
				// console.log('close');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shopping-comment {
		.list {
			.list-item {
				display: flex;
				margin-bottom: 56rpx;
				padding: 0 32rpx;
				font-size: 30rpx;

				&+.list-item {
					margin-top: 12rpx;
				}

				.image {
					height: 80rpx;
					min-width: 80rpx;
					max-width: 80rpx;
					margin-right: 24rpx;
					border-radius: 8rpx;
				}

				.tips {
					display: flex;
					flex-direction: column;
					height: 80rpx;
					justify-content: space-between;
					flex: 1;

					.text {
						width: 550rpx;
						overflow: hidden;
						white-space: nowrap;
						word-break: break-all;
						text-overflow: ellipsis;
					}
				}
			}
		}

		.box {
			.btn {
				margin: 0 auto;
				margin-top: 10rpx;
				margin-bottom: calc(env(safe-area-inset-bottom) + 78rpx);
				width: 686rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				background: #FD8F19;
				border-radius: 40rpx;
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;
			}


			.header {
				position: relative;

				.title {
					width: 100%;
					text-align: center;
					font-size: 30rpx;
					font-weight: 500;
					color: #1F1F1F;
				}

				.icon-close {
					position: absolute;
					right: 32rpx;
					top: 50%;
					transform: translate(0, -50%);
					background-color: #F1F1F1;
					height: 38rpx;
					width: 38rpx;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}
	}
</style>
